package com.david.zhufengfm.client;

import android.util.Log;

import com.david.zhufengfm.entity.album.PlayTrack;
import com.david.zhufengfm.utils.HttpTools;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Created by David on 2015/10/20.
 * qq:978944820
 */
public final class ClientAPI {
    /**
     * 单独提取服务器地址的部分，避免以后更换服务器地址
     */
    public static final String API_POINT="http://mobile.ximalaya.com";
    private ClientAPI(){

    }
    //-----------------------------------
    //接口12

    /**
     * 获取发现分类
     * API地址：/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2
     * @return JSONObject
     */
    public static JSONObject getDiscoverCategories(){
        JSONObject ret=null;
        byte[] data = HttpTools.doGet(API_POINT
                + "/mobile/discovery/v1/categories?device=android&picVersion=10&scale=2");
        if (data != null) {
            try {
                String str=new String(data,"UTF-8");
                ret=new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }
    //--------------------------------------------------------------------
    //接口11
    //channel 渠道

    /**
     * 获取发现部分，推荐列表的内容
     * 请求网址：/mobile/discovery/v1/recommends?channel=and-f6&device=android&includeActivity=true&includeSpecial=true&scale=2&version=4.1.7.1
     * @param channel //软件发布渠道
     * @param includeActivity //是否包含活动
     * @param includeSpecial //是否包含"精品听单"
     * @return
     */
    public static JSONObject getDisCoverRecommend(
            String channel,boolean includeActivity,
            boolean includeSpecial){
        JSONObject ret=null;
        if (channel == null) {
            channel="and-f6";
        }
        String url=API_POINT
                +"/mobile/discovery/v1/recommends"
                +"?channel="+channel
                +"&device=android"
                +"&includeActivity="+includeActivity
                +"&includeSpecial="+includeSpecial
                +"&scale=2&version=4.1.7.1";
        Log.i("url",url);
        byte[] data = HttpTools.doGet(url);
        if (data != null) {
            try {
                String str=new String(data,"UTF-8");
                ret=new JSONObject(str);
                Log.i("str",str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    public static JSONObject getAlbumDetail(long albumId){
        JSONObject ret=null;

        String url="http://mobile.ximalaya.com/mobile/others/ca/album/track/"
                + albumId
                + "/true/1/20?device=android&pageSize=20&albumId=203355&isAsc=true";

        byte[] data = HttpTools.doGet(url);
        if (data != null) {
            try {
                String str=new String(data,"UTF-8");
                ret=new JSONObject(str);
                Log.i("str",str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;

    }
    public static  JSONObject getPlayList(long albumId,long trackId){
        JSONObject ret=null;
        String url="http://mobile.ximalaya.com/mobile/playlist/album?device=android"
                + "&albumId=" + albumId
                + "&trackId="+trackId;
        byte[] data = HttpTools.doGet(url);
        if (data != null) {
            try {
                String str=new String(data,"UTF-8");
                ret=new JSONObject(str);
                Log.i("str",str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;

    }
}
